deterministic algorithm